package utils

import "golang.org/x/crypto/bcrypt"

// 生成密码(接收用户的密码)
func HashPassword(password string) (string, error) {
	hashBytes, err := bcrypt.GenerateFromPassword([]byte(password), 11)
	return string(hashBytes), err
}

// 验证密码(传递明文密码和哈希后的密码)
func CheckPasswordHash(password string, hash string) bool {
	err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
	return err == nil
}
